#ifndef __CLOG_COMMON_H__
#define __CLOG_COMMON_H__

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>

#define MAX_MODULE_NUM 10
#define CLOG_DEBUG   1

enum ERR_CODE {
    ERR_CODE_OK = 0,
    ERR_CODE_ERR,
    ERR_CODE_PARSE_JSON_FAIL, /* parse json fail */
    ERR_CODE_JSON_CHECK_FAIL, /* json parameter check failed */
    ERR_CODE_MALLOC, /* malloc err */
    ERR_CODE_OPEN_FILE, /* open file err */
    ERR_CODE_INVALID_PARAM, /* invalid parameter */
    ERR_CODE_RING_BUF_FULL, /* ring buf full */
    ERR_CODE_RING_BUF_EMPTY, /* ring buf empty */
    ERR_CODE_RING_BUF_LOCK, /* ring buf lock */
};

#ifndef RET_OK
#define RET_OK ERR_CODE_OK /* ret ok */
#endif

#ifndef RET_ERR
#define RET_ERR -ERR_CODE_ERR /* ret err */
#endif

typedef struct {
    uint32_t module_id;
    uint32_t module_enable;
    const char* log_level;
    const char* shm_key;
    const char* log_file;
    const char* module_name;
    uint8_t *tmp_buf;
    uint32_t tmp_buf_size;
    uint64_t log_file_size;
    uint8_t is_task_enqueued;
    pthread_mutex_t tmp_buf_mutex;
    char log_file_name[256];
    FILE *log_file_fp;
    uint64_t last_write_time;
}module_info_t;

typedef struct {
    uint32_t module_num;
    module_info_t module_info[MAX_MODULE_NUM];
}module_info_list_t;

typedef struct {
    uint32_t debug_level;
    const char* log_level;
    const char* log_dir;
    const char* log_file;
    uint32_t log_file_size;
    uint32_t ring_bufs_size;
    uint32_t async_buf_size;
    uint32_t async_interval;
    uint32_t shm_size;
    bool should_stop;
    pthread_t read_thread;
}global_info_t;

typedef struct {
    global_info_t global_info;
    module_info_list_t module_info_list;
}clog_config_t;

#define CLOG_PARSE_LENGTH 28

#endif